var app = getApp();
function goToGood(id) {
    wx.navigateTo({
        url: "/pages/good/good?id=" + id,
    })
}

function goToStore(id) {
    wx.navigateTo({
        url: "/pages/store/store?id=" + id,
    })
}

function backToGood(id){
    var pages = getCurrentPages();
    var delta = 0;
    app.globalData.goodId = id;
    for(var i=0;i<pages.length;i++){
        if(pages[i].__route__ == "pages/good/good"){
            delta = pages.length - 1 - i;
        }
    }
    console.log(delta);
    console.log(id);
    wx.navigateBack({
      delta: delta, 
    })
}

function checkLogin(redirect_uri) {
    var session = wx.getStorageSync('session');
    if (session) {
        return true;
    } else {
        wx.navigateTo({
            url: '/pages/login/login?redirect_uri=' + redirect_uri
        })
        return false;
    }
}

module.exports = {
    goToGood: goToGood,
    goToStore: goToStore,
    backToGood: backToGood,
    checkLogin: checkLogin
}